define(function(require, exports, module) {
	J = jQuery;
	require('bootstrap');
	require('layer');
	require('qqFace');
	require('datetimepicker');
	layer.config({
	    path: '/assets/vendors/layer/' //layer.js所在的目录，可以是绝对目录，也可以是相对目录
	});
	var timenow = new Date().getTime();
	
	var userlogin=0;
	$.ajax({
        type: "get",
        contentType: "application/json",
        url: "/member/ajaxlogin.json?&"+Math.random(),
        data: "{}",
        dataType: 'json',
        async: false, //ajax方法外可以调用变量
        success: function(data) {
        	if(data.code >= 0){
        		userlogin=1;
	        }
        }
    });
	
	$("#post-thread-btn").on("click",function(event){
		var parent_id = $("#post_parent_id").val();
		var content = $("#replycontent1").val();
		var typeid = $("#typeid").val();
		var type = $("#type").val();				
		if(content.length>=2){
			$("#replycontent1").closest('div').removeClass('has-error').addClass('has-success');
		}else{
			$("#replycontent1").closest('div').removeClass('has-success').addClass('has-error');
			$("#replycontent1").focus();
			return false;
		}
		$.ajax({
    		url: "/member/addComment.json?"+timenow,
    		data: {"typeid":typeid,"type":type,"parent_id":parent_id,"content":content},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('发送错误', {icon: 2});
    		},
    		success: function(ret){
				if (ret.code >= 0) {
					layer.msg("提交成功！", {icon: 1});
					$("#replycontent1").val("");
					window.location.reload();
	        		return false;
				} else {
					layer.msg(ret.message, {icon: 5});
					return false;
				}
          	}
    	});
		return false;
	});
	
	$(".emoji-wysiwyg-editor").on("blur", function(){
		var content=$(this).html();
		var replycontent=$(this).parent().prev('label').attr("for");
		if(content.length>0){
			$("#"+replycontent).val(content);
		}
	});
	
	$('#createTime').datetimepicker({
	lang:'ch',
		format:'Y-m-d H:i:s',
		step:5
	});
	
	
	$(".reply-btn").on("click",function(){
		//alert("sdfsdfsd");
		var postid=$(this).attr("data-id");
		var parentid = $("#parent_id-"+postid).val();
		var content = $("#replycontent"+postid).val();	
		var to_uid = $("#to_uid-"+postid).val();
		var typeid = $("#typeid-"+postid).val();
		if(content.length>=2){
			$("#replycontent"+postid).closest('div').removeClass('has-error').addClass('has-success');
		}else{
			$("#replycontent"+postid).closest('div').removeClass('has-success').addClass('has-error');
			$("#replycontent"+postid).focus();
			return false;
		}
		
		$.ajax({
			url: "/member/addComment.json?"+timenow,
			data: {"typeid":typeid,"type":1,"parent_id":parentid,"content":content,"to_uid":to_uid},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('发送错误', {icon: 2});
    		},
    		success: function(data){	
    			if(data.code>=0){
    				layer.msg("提交成功！", {icon: 1});
    				window.location.reload();
    				return false;
    			}else{
					if(data.message!=''){
						layer.msg(data.message, {icon: 2});
						return false;
					}
				}
          	}
    	});
		return false;
	});
	
	var articleid=$("#countview").attr("data-article-id");
	if(articleid>=0){
		$.getJSON("/article/viewcount.htm?"+timenow,{"article_id":articleid},function(result){
	    	$("#countview").html(result);
		});
	}
	
	//回复用户
	$(".commentReply").on("click", function(){
		var postid=$(this).attr("data-id");
		var replyid=$(this).attr("reply-id");
		var postname=$(this).attr("data-username");
		var userid=$(this).attr("data-userid");
		$("#parent_id-"+postid).val(replyid);
		$("#to_uid-"+postid).val(userid);
		$("#replycontent"+postid).attr("placeholder","对"+postname+"说：");
		$("#replycontent"+postid).focus();
	});
	
	$(".unreply").on("click", function(){
		var postid=$(this).attr("postid");
		if($(".reply-"+postid).css("display")!="none"){
			$(".reply-"+postid).css("display","none");
			$(".unreply").css("display","none");
			$(".reply").css("display","block");
			$("#comment-reply-"+postid).css("display","none");
		}
	});
	
	$(".reply").on("click", function(){
		var postid=$(this).attr("postid");
		if($(".reply-"+postid).css("display")!="block"){
			$(".reply-"+postid).css("display","block");			
		}
		$("#unreply-"+postid).css("display","block");
		$("#reply-"+postid).css("display","none");
		$("#comment-reply-"+postid).css("display","block");
	});
	//回复评论	
	$(".comments").on("click", function(){
		var userid=$(this).attr("data-userid");
		var postid=$(this).attr("data-id");
		//var content = $("#reply-content-"+postid).val();
		var postname=$(this).attr("data-username");
		
		$("#to_uid-"+postid).val(userid);
		$("#parent_id-"+postid).val(postid);
		$("#replycontent"+postid).attr('placeholder','说出您对评论者的意见与看法！');
		$("#replycontent"+postid).focus();
	});
	
	//回复评论	
	$(".comments").on("click", function(){
		var postid=$(this).attr("data-id");
		if($("#comment-"+postid).hasClass("hidden")){
	    	$("#comment-"+postid).removeClass("hidden");
    	}else{
	    	$("#comment-"+postid).addClass("hidden");
    	}
	});
		
	$(function(){
		$('.emotion-expand-btn').qqFace({
			id:'facebox', //表情盒子的ID
			assign:'replycontent', //给那个控件赋值
			path:'/assets/images/qqFace/'	//表情存放的路径
		});
	});
	

	//删除话题操作
	$("#deteletopic").on("click", function(){
		var topicid=$(this).attr("id-topic");
		var groupid=$(this).attr("id-group");
		layer.confirm('您确定要删除该话题？', {
		    btn: ['确定','取消'] //按钮
		}, function(){
			$.ajax({
	    		url: '/member/topic/delete.json', 
	    		data: {'topic_id': topicid},
	    		dataType: "json",
	    		type :  "get",
	    		cache : false,
	    		async: false,
	    		error : function(i, g, h) {
	    			layer.msg('发送错误', {icon: 2});
	    		},
	    		success: function(data){	
	    			if(data.code==0){
	    				window.location.href = "/group/"+groupid+"/";
	    				return false;
	    			}else{
						if(data.message!=''){
							layer.msg(data.message, {icon: 2});
							return false;
						}
					}
	          	}
	    	});
		}, function(){
		});
		return false;
	});
	
	;(function ($) {
		$.extend({
			tipsBox: function (options) {
				options = $.extend({
					obj: "count",  //jq对象，要在那个html标签上显示
					str: "+1",  //字符串，要显示的内容;也可以传一段html，如: "<b style='font-family:Microsoft YaHei;'>+1</b>"
					startSize: "18px",  //动画开始的文字大小
					endSize: "38px",    //动画结束的文字大小
					interval: 600,  //动画时间间隔
					color: "red",    //文字颜色
					callback: function () { }    //回调函数
				}, options);
				$("body").append("<span class='count1'>" + options.str + "</span>");
				var box = $(".count1");
				var left = options.obj.offset().left + options.obj.width() / 2;
				var top = options.obj.offset().top - options.obj.height();
				box.css({
					"position": "absolute",
					"left": left + "px",
					"top": top + "px",
					"z-index": 9999,
					"font-size": options.startSize,
					"line-height": options.endSize,
					"color": options.color
				});
				box.animate({
					"font-size": options.endSize,
					"opacity": "0",
					"top": top - parseInt(options.endSize) + "px"
				}, options.interval, function () {
					box.html("hhhhh");
					options.callback();
				});
			}
		});
	})(jQuery);
	
	//点击收藏
	$("#sideBookmark").on("click", function(){
		//alert(user.uid);
		if(user.uid!=0){
			var dataid=$(this).attr("data-id");
			$.ajax({
	    		url: '/member/favoritearticle.json', 
	    		data: {'info_id': dataid},
	    		dataType: "json",
	    		type :  "get",
	    		cache : false,
	    		async: false,
	    		error : function(i, g, h) {
	    			layer.msg('发送错误', {icon: 2});
	    		},
	    		success: function(data){	
	    			if(data.code==0){
	    				layer.msg('已收藏', {icon: 1});
	    				return false;
	    			}else{
						if(data.message!=''){
							layer.msg(data.message, {icon: 2});
							return false;
						}
					}
	          	}
	    	});
		}else{
			layer.msg("请登录后收藏！", {icon: 2});
		}
		
	});
	
	$('#myCarousel').carousel({
		interval: 4000
	});

	
	$('[id^=carousel-selector-]').click( function(){
	  var id_selector = $(this).attr("id");
	  var id = id_selector.substr(id_selector.length -1);
	  id = parseInt(id);
	  $('#myCarousel').carousel(id);
	  $('[id^=carousel-selector-]').removeClass('selected');
	  $(this).addClass('selected');
	});

	
	$('#myCarousel').on('slid', function (e) {
	  var id = $('.item.active').data('slide-number');
	  id = parseInt(id);
	  $('[id^=carousel-selector-]').removeClass('selected');
	  $('[id=carousel-selector-'+id+']').addClass('selected');
	});

	
//	$(function(){
//        $(".text-fmt > p").removeAttr("class").removeAttr("id").css({ "width": "100%"});
//    });
	  
	function niceIn(prop){
		prop.find('i').addClass('niceIn');
		setTimeout(function(){
			prop.find('i').removeClass('niceIn');	
		},1000);		
	}

});